<html>
<head><meta charset="utf-8"><title>occurs check for constants  #74040 · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html">occurs check for constants  #74040</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205291297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291297">(Jul 28 2020 at 21:11)</a>:</h4>
<p>Hey <span class="user-mention" data-user-id="216206">@lcnr</span> have a second to discuss <a href="https://github.com/rust-lang/rust/pull/74040">https://github.com/rust-lang/rust/pull/74040</a> ?</p>



<a name="205291307"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291307" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291307">(Jul 28 2020 at 21:11)</a>:</h4>
<p>yeah</p>



<a name="205291332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291332">(Jul 28 2020 at 21:11)</a>:</h4>
<p>So</p>



<a name="205291339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291339">(Jul 28 2020 at 21:11)</a>:</h4>
<p>I was looking at your "motivating example"</p>



<a name="205291389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291389">(Jul 28 2020 at 21:12)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="w">    </span><span class="sd">/// fn bind&lt;const N: usize&gt;(value: [u8; N]) -&gt; [u8; 3 + 4] {</span>
<span class="w">    </span><span class="sd">///     todo!()</span>
<span class="w">    </span><span class="sd">/// }</span>
<span class="w">    </span><span class="sd">///</span>
<span class="w">    </span><span class="sd">/// fn main() {</span>
<span class="w">    </span><span class="sd">///     let mut arr = Default::default();</span>
<span class="w">    </span><span class="sd">///     arr = bind(arr);</span>
<span class="w">    </span><span class="sd">/// }</span>
</code></pre></div>



<a name="205291408"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291408" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291408">(Jul 28 2020 at 21:12)</a>:</h4>
<p>are you saying that this code should not compile?</p>



<a name="205291431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291431">(Jul 28 2020 at 21:12)</a>:</h4>
<p>This code should compile</p>



<a name="205291459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291459">(Jul 28 2020 at 21:13)</a>:</h4>
<p>but with the way <code>ty::Generics</code> and lazy norm currently works it causes problems</p>



<a name="205291471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291471">(Jul 28 2020 at 21:13)</a>:</h4>
<p>OK, so I think the idea is that the occurs check will reject some attempt at unification</p>



<a name="205291476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291476">(Jul 28 2020 at 21:13)</a>:</h4>
<p>and force us down a different path?</p>



<a name="205291504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291504">(Jul 28 2020 at 21:13)</a>:</h4>
<p>also, this is presumably a blocker to the "min const generics" stabilization?</p>



<a name="205291566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291566">(Jul 28 2020 at 21:13)</a>:</h4>
<p>So the occurs check rejects unifying <code>N</code> with <code>{ N + 1 }</code></p>



<a name="205291680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291680">(Jul 28 2020 at 21:14)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040/near/205291504">said</a>:</p>
<blockquote>
<p>also, this is presumably a blocker to the "min const generics" stabilization?</p>
</blockquote>
<p>luckily no, this is only problematic when dealing with <code>ConstKind::Unevaluated</code> and lazy norm</p>



<a name="205291753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291753">(Jul 28 2020 at 21:15)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040/near/205291566">said</a>:</p>
<blockquote>
<p>So the occurs check rejects unifying <code>N</code> with <code>{ N + 1 }</code></p>
</blockquote>
<p>but because we currently use the parent generics in <code>ConstKind::Unevaluated</code>, we also reject unifying <code>N</code> with <code>1 + 2</code> if <code>1 +2</code> has the wrong parent generics</p>



<a name="205291773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291773">(Jul 28 2020 at 21:15)</a>:</h4>
<p>i.e. we can't currently know that <code>1 + 2</code> does not use<code>N</code></p>



<a name="205291789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291789">(Jul 28 2020 at 21:15)</a>:</h4>
<p>Hmm</p>



<a name="205291792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291792">(Jul 28 2020 at 21:15)</a>:</h4>
<p>I am wondering</p>



<a name="205291855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291855">(Jul 28 2020 at 21:16)</a>:</h4>
<p>How would you feel about scheduling some time to do a recorded walk through of how const generics is working?</p>



<a name="205291859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291859">(Jul 28 2020 at 21:16)</a>:</h4>
<p>i.e., we talk out some examples</p>



<a name="205291867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291867">(Jul 28 2020 at 21:16)</a>:</h4>
<p>or we could do it on zulip if you prefer</p>



<a name="205291873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291873">(Jul 28 2020 at 21:16)</a>:</h4>
<p>but zoom might be higher bandwidth</p>



<a name="205291878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291878">(Jul 28 2020 at 21:16)</a>:</h4>
<p>I'm thinking it'd be a good rustc lecture series entry :)</p>



<a name="205291889"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291889" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291889">(Jul 28 2020 at 21:16)</a>:</h4>
<p>I am feeling a desire to better understand the details here...</p>



<a name="205291927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291927">(Jul 28 2020 at 21:17)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040/near/205291773">said</a>:</p>
<blockquote>
<p>i.e. we can't currently know that <code>1 + 2</code> does not use<code>N</code></p>
</blockquote>
<p>yeah this is interesting. I mean the "min const generics" proposal actually <em>does</em> require us to know that, right? But we regard that as something of a temporary crutch?</p>



<a name="205291944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205291944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205291944">(Jul 28 2020 at 21:17)</a>:</h4>
<p>i.e., there is that edge case of <code>u8::FOO</code> that could be expanded to <code>&lt;u8 as Trait&lt;T&gt;&gt;::FOO</code></p>



<a name="205292027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292027">(Jul 28 2020 at 21:18)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040/near/205291855">said</a>:</p>
<blockquote>
<p>How would you feel about scheduling some time to do a recorded walk through of how const generics is working?</p>
</blockquote>
<p>yeah, I have a small amount of imposter syndrome here, but I think this should be something I can do</p>



<a name="205292038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292038">(Jul 28 2020 at 21:18)</a>:</h4>
<p>zoom is fine for me</p>



<a name="205292050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292050">(Jul 28 2020 at 21:18)</a>:</h4>
<p>You Can Do It! <span aria-label="tada" class="emoji emoji-1f389" role="img" title="tada">:tada:</span></p>



<a name="205292053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292053">(Jul 28 2020 at 21:18)</a>:</h4>
<p>in any case, the idea would be to talk together</p>



<a name="205292064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292064">(Jul 28 2020 at 21:18)</a>:</h4>
<p>i.e., I've got lots of questions so it's not like you have to prepare some kind of script</p>



<a name="205292065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292065">(Jul 28 2020 at 21:18)</a>:</h4>
<blockquote>
<p>the "min const generics" proposal actually does require us to know that, right?</p>
</blockquote>
<p>nope, we never use the parent generics in "min const generics"</p>



<a name="205292069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292069">(Jul 28 2020 at 21:18)</a>:</h4>
<p>well yeah but</p>



<a name="205292074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292074">(Jul 28 2020 at 21:19)</a>:</h4>
<p>the reason we can get away with that</p>



<a name="205292090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292090">(Jul 28 2020 at 21:19)</a>:</h4>
<p>is because we are scanning for generic type parameters in the expression</p>



<a name="205292093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292093">(Jul 28 2020 at 21:19)</a>:</h4>
<p>So we never have to deal with <code>ConstKind::Unevaluated</code> with generics</p>



<a name="205292094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292094">(Jul 28 2020 at 21:19)</a>:</h4>
<p>and erroring if we see them</p>



<a name="205292206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292206">(Jul 28 2020 at 21:20)</a>:</h4>
<p>na, I currently check this during name resolution and only allow <code>N</code> or <code>{ N }</code></p>



<a name="205292249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292249">(Jul 28 2020 at 21:20)</a>:</h4>
<p>so we never create any <code>ConstKind::Unevaluated</code> which could contain generic parameters</p>



<a name="205292261"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292261" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292261">(Jul 28 2020 at 21:20)</a>:</h4>
<p>right but what I'm saying is</p>



<a name="205292293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292293">(Jul 28 2020 at 21:21)</a>:</h4>
<p>we believe that we can detect expressions that definitely do not reference generic parameters</p>



<a name="205292320"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292320" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292320">(Jul 28 2020 at 21:21)</a>:</h4>
<p>basically I'm contemplating the weirdness that <code>3+4</code> is considered to potentially depend on the parent generics :)</p>



<a name="205292340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292340">(Jul 28 2020 at 21:21)</a>:</h4>
<p>anyway, this is a bit off topic</p>



<a name="205292389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292389">(Jul 28 2020 at 21:22)</a>:</h4>
<p>I guess I want to walk through the example with lazy-norm to understand what's going on</p>



<a name="205292443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292443">(Jul 28 2020 at 21:23)</a>:</h4>
<blockquote>
<p>I'm contemplating the weirdness that 3+4 is considered to potentially depend on the parent generics</p>
</blockquote>
<p>yeah, I am not sure if a partial solution is a good idea though</p>



<a name="205292465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292465">(Jul 28 2020 at 21:23)</a>:</h4>
<p>There might be a good subset which should be fine</p>



<a name="205292500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292500">(Jul 28 2020 at 21:23)</a>:</h4>
<p>similar to what's the plan with const wf, so this might work</p>



<a name="205292578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292578">(Jul 28 2020 at 21:24)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040/near/205292389">said</a>:</p>
<blockquote>
<p>I guess I want to walk through the example with lazy-norm to understand what's going on</p>
</blockquote>
<p>now?</p>



<a name="205292606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292606">(Jul 28 2020 at 21:24)</a>:</h4>
<p>maybe:)</p>



<a name="205292617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292617">(Jul 28 2020 at 21:24)</a>:</h4>
<p>maybe not</p>



<a name="205292628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292628">(Jul 28 2020 at 21:25)</a>:</h4>
<p>I mean the PR seems ok I just don't have a complete picture</p>



<a name="205292633"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292633" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292633">(Jul 28 2020 at 21:25)</a>:</h4>
<p>of the context</p>



<a name="205292643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292643">(Jul 28 2020 at 21:25)</a>:</h4>
<p>okay</p>



<a name="205292715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292715">(Jul 28 2020 at 21:25)</a>:</h4>
<p>let me try to explain this rn, and if it doesn't work we can reschedule this and do it over zoom</p>



<a name="205292781"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292781" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292781">(Jul 28 2020 at 21:26)</a>:</h4>
<p>Let's use this example:</p>
<div class="codehilite"><pre><span></span><code><span class="cp">#![feature(const_generics)]</span><span class="w"> </span><span class="c1">//~ WARN the feature `const_generics` is incomplete</span>

<span class="k">fn</span> <span class="nf">bind</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">(</span><span class="n">value</span>: <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="p">])</span><span class="w"> </span>-&gt; <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">4</span><span class="p">]</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">todo</span><span class="o">!</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">arr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Default</span>::<span class="n">default</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">arr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bind</span><span class="p">(</span><span class="n">arr</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="c1">//~^ ERROR mismatched types</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="205292933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292933">(Jul 28 2020 at 21:28)</a>:</h4>
<p>we call <code>bind</code> here and constrain <code>arr</code> to <code>[u8; _#1c]</code> (or <code>[u8; N]</code>, whatever)</p>



<a name="205292944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292944">(Jul 28 2020 at 21:28)</a>:</h4>
<p>right so</p>



<a name="205292967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292967">(Jul 28 2020 at 21:28)</a>:</h4>
<p>to start, <code>arr</code> will be <code>?X</code> (i.e., after the call to <code>Default</code>)</p>



<a name="205292995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205292995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205292995">(Jul 28 2020 at 21:28)</a>:</h4>
<p>we'll instantiate a <code>_#1c</code> for the <code>N</code> parameter when we call <code>bind</code></p>



<a name="205293022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293022">(Jul 28 2020 at 21:29)</a>:</h4>
<p>the signature of <code>bind</code> is then <code>[u8; ?N]</code> (let's use that notation, easier to type)</p>



<a name="205293042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293042">(Jul 28 2020 at 21:29)</a>:</h4>
<p>when we relate <code>?X</code> and <code>[u8; ?N]</code>, do we generalize <code>?N</code> to a <code>?M</code>?</p>



<a name="205293051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293051">(Jul 28 2020 at 21:29)</a>:</h4>
<p>(maybe not relevant, just checking)</p>



<a name="205293060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293060">(Jul 28 2020 at 21:29)</a>:</h4>
<p>or do we not because constants are only equal if they're equal I guess</p>



<a name="205293121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293121">(Jul 28 2020 at 21:30)</a>:</h4>
<p>(mm well that's not entirely true, there can be multiple constants that evaluate to one another...)</p>



<a name="205293165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293165">(Jul 28 2020 at 21:30)</a>:</h4>
<p>I guess based on your comment that we would not generalize <code>?N</code> and hence we just bind <code>?X</code> to the value <code>[u8; ?N]</code></p>



<a name="205293185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293185">(Jul 28 2020 at 21:31)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040/near/205293042">said</a>:</p>
<blockquote>
<p>when we relate <code>?X</code> and <code>[u8; ?N]</code>, do we generalize <code>?N</code> to a <code>?M</code>?</p>
</blockquote>
<p>I don't think so, but I also don't think this matters as consts must be exactly equal (no subtyping)</p>



<a name="205293314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293314">(Jul 28 2020 at 21:32)</a>:</h4>
<p>yeah i'm not entirely sure</p>



<a name="205293315"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293315" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293315">(Jul 28 2020 at 21:32)</a>:</h4>
<p>I am certain that we bind <code>?X</code> to <code>[u8; ?Q]</code> where <code>?Q</code> unifies with <code>?N</code></p>



<a name="205293326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293326">(Jul 28 2020 at 21:32)</a>:</h4>
<p>I think you're right it doesn't matter, but only if we get everything else right ;)</p>



<a name="205293340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293340">(Jul 28 2020 at 21:32)</a>:</h4>
<p>anyway ok</p>



<a name="205293379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293379">(Jul 28 2020 at 21:33)</a>:</h4>
<p>so the return type of <code>bind(arr)</code> is then <code>[u8; 3+4]</code>, but <code>3+4</code> is actually an "unevaluated" with the parent generics</p>



<a name="205293396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293396">(Jul 28 2020 at 21:33)</a>:</h4>
<p>which means it is like <code>Unevaluated&lt;?N&gt;(3+4)</code> or something</p>



<a name="205293401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293401">(Jul 28 2020 at 21:33)</a>:</h4>
<p>yeah</p>



<a name="205293406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293406">(Jul 28 2020 at 21:33)</a>:</h4>
<p>so then we attempt to unify that with <code>?N</code> -- and this is where your PR interferes</p>



<a name="205293411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293411">(Jul 28 2020 at 21:33)</a>:</h4>
<p>until now, I guess, that unification succeeds</p>



<a name="205293423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293423">(Jul 28 2020 at 21:33)</a>:</h4>
<p>but with your PR, it fails because the <code>?N</code> is part of the generics?</p>



<a name="205293435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293435">(Jul 28 2020 at 21:33)</a>:</h4>
<p>so what about an example like</p>



<a name="205293489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293489">(Jul 28 2020 at 21:34)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">bind</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">C</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">(</span><span class="n">x</span>: <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">C</span><span class="p">])</span><span class="w"> </span>-&gt; <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">C</span><span class="p">]</span><span class="w"></span>
</code></pre></div>



<a name="205293499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293499">(Jul 28 2020 at 21:34)</a>:</h4>
<p>and then <code>arr = bind(arr)</code></p>



<a name="205293514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293514">(Jul 28 2020 at 21:34)</a>:</h4>
<p>well wait</p>



<a name="205293519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293519">(Jul 28 2020 at 21:34)</a>:</h4>
<p>don't answer that</p>



<a name="205293534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293534">(Jul 28 2020 at 21:34)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040/near/205293423">said</a>:</p>
<blockquote>
<p>but with your PR, it fails because the <code>?N</code> is part of the generics?</p>
</blockquote>
<p>so, it fails, and then we fall back to some other path where we evaluate the <code>3+4</code>?</p>



<a name="205293540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293540">(Jul 28 2020 at 21:34)</a>:</h4>
<p>(where is that path)</p>



<a name="205293584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293584">(Jul 28 2020 at 21:35)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040/near/205293534">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040/near/205293423">said</a>:</p>
<blockquote>
<p>but with your PR, it fails because the <code>?N</code> is part of the generics?</p>
</blockquote>
<p>so, it fails, and then we fall back to some other path where we evaluate the <code>3+4</code>?</p>
</blockquote>
<p>we aren't doing so rn, at least not intentionally <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="205293688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293688">(Jul 28 2020 at 21:36)</a>:</h4>
<p>ok :)</p>



<a name="205293690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293690">(Jul 28 2020 at 21:36)</a>:</h4>
<p>so how does it succeed?</p>



<a name="205293703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293703">(Jul 28 2020 at 21:36)</a>:</h4>
<p>That test doesn't</p>



<a name="205293718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293718">(Jul 28 2020 at 21:36)</a>:</h4>
<div class="codehilite"><pre><span></span><code>error[E0308]: mismatched types
  --&gt; $DIR/unused-substs-4.rs:9:11
   |
LL |     arr = bind(arr);
   |           ^^^^^^^^^ encountered a self-referencing constant
</code></pre></div>



<a name="205293752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293752">(Jul 28 2020 at 21:37)</a>:</h4>
<p>OK, but earlier you wrote that it was meant to work</p>



<a name="205293760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293760">(Jul 28 2020 at 21:37)</a>:</h4>
<p>so is that a "FIXME"?</p>



<a name="205293801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293801">(Jul 28 2020 at 21:37)</a>:</h4>
<p>somewhat</p>



<a name="205293870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293870">(Jul 28 2020 at 21:38)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> mentioned that we might try to eagerly evaluate <code>3 + 4</code> if the occurs check fails</p>



<a name="205293885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293885">(Jul 28 2020 at 21:38)</a>:</h4>
<p>but that seems non trivial to me (as it can cause cycle errors and stuff)</p>



<a name="205293890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293890">(Jul 28 2020 at 21:38)</a>:</h4>
<p>yeah, this is the thing I'd like to talk over in more detail</p>



<a name="205293895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293895">(Jul 28 2020 at 21:38)</a>:</h4>
<p>that doesn't feel "right"</p>



<a name="205293899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293899">(Jul 28 2020 at 21:38)</a>:</h4>
<p>though maybe it is :P</p>



<a name="205293904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205293904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205293904">(Jul 28 2020 at 21:38)</a>:</h4>
<p>so I would try it in a future PR if it seems needed</p>



<a name="205294012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205294012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205294012">(Jul 28 2020 at 21:40)</a>:</h4>
<p>"if it seems needed" --</p>



<a name="205294023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205294023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205294023">(Jul 28 2020 at 21:40)</a>:</h4>
<p>eventually we'll need <em>some</em> solution to this</p>



<a name="205294032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205294032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205294032">(Jul 28 2020 at 21:40)</a>:</h4>
<p>so does that mean "if we don't find a better alternative" or something like that?</p>



<a name="205294144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205294144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205294144">(Jul 28 2020 at 21:42)</a>:</h4>
<p>"if it seems needed" mostly means once all more important issues have been dealt with</p>



<a name="205294228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205294228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205294228">(Jul 28 2020 at 21:42)</a>:</h4>
<p>I suspect there is no good solution here as long as we keep using the parent generics</p>



<a name="205294398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205294398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205294398">(Jul 28 2020 at 21:44)</a>:</h4>
<p>but there are also quite a few issues with doing so and it will be quite a lot of work to get this right (if we even want to)</p>



<a name="205294567"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205294567" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205294567">(Jul 28 2020 at 21:46)</a>:</h4>
<p>I left a review</p>



<a name="205294587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205294587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205294587">(Jul 28 2020 at 21:46)</a>:</h4>
<p>mostly it talks about the universe question</p>



<a name="205294637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205294637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205294637">(Jul 28 2020 at 21:47)</a>:</h4>
<p>re: the parent generics, clearly we sometimes have to, but we may also be able to figure out when we don't, but the identify case is interesting</p>



<a name="205294655"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205294655" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205294655">(Jul 28 2020 at 21:47)</a>:</h4>
<p>there are also cases like <code>&lt;T as Foo&lt;N&gt;&gt;::BAR</code> which maybe doesn't really care what <code>N</code> is</p>



<a name="205294687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205294687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205294687">(Jul 28 2020 at 21:47)</a>:</h4>
<p>yeah, it's an interesting problem</p>



<a name="205294772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205294772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205294772">(Jul 28 2020 at 21:48)</a>:</h4>
<p>We also have </p>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">bind</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">M</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">(</span><span class="n">value</span>: <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="p">])</span><span class="w"> </span>-&gt; <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">M</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">todo</span><span class="o">!</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="205294845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205294845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205294845">(Jul 28 2020 at 21:49)</a>:</h4>
<p>(gotta run now though)</p>



<a name="205294847"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205294847" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205294847">(Jul 28 2020 at 21:49)</a>:</h4>
<p>which won't cause problems with the example from above (because we can't infer the array length just from <code>bind</code> anymore)</p>



<a name="205297443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205297443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205297443">(Jul 28 2020 at 22:18)</a>:</h4>
<p>oh, I just realized that we can pretty much fix this much doing polymorphization on <code>mir_validated</code>/<code>mir_const</code></p>



<a name="205297504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205297504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205297504">(Jul 28 2020 at 22:19)</a>:</h4>
<p>for constants</p>



<a name="205297786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205297786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205297786">(Jul 28 2020 at 22:23)</a>:</h4>
<p>will elaborate tomorrow if needed</p>



<a name="205331260"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205331260" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205331260">(Jul 29 2020 at 08:49)</a>:</h4>
<p>Okay, so now that I slept over this and spend a bit more time thinking about it, I wasn't able to think of any big problems with this approach</p>



<a name="205331407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205331407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205331407">(Jul 29 2020 at 08:51)</a>:</h4>
<p>Similar to what I wanted to do with const wf bounds, this would need to use unoptimized mir to prevent us relying on optimizations: e.g.</p>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span>: <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">std</span>::<span class="n">mem</span>::<span class="n">size_of</span>::<span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="mi">7</span><span class="w"></span>
<span class="w">    </span><span class="p">}];</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="205331545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205331545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205331545">(Jul 29 2020 at 08:52)</a>:</h4>
<p>If we were to use <code>optimized_mir</code> here, removing <code>std::mem::size_of::&lt;T&gt;()</code> in an optimization would suddenly be part of our stability guarantees.</p>



<a name="205331834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205331834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205331834">(Jul 29 2020 at 08:56)</a>:</h4>
<p>I guess one concern will be performance, as we would have to look at a lot more mir than what can be found in <code>optimized_mir</code>, so it is slightly slower. We can only run this check for anon consts where this is relevant, so the impact will hopefully be minimal</p>



<a name="205331897"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205331897" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205331897">(Jul 29 2020 at 08:57)</a>:</h4>
<p>going back to the above example:</p>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">bind</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">(</span><span class="n">value</span>: <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="p">])</span><span class="w"> </span>-&gt; <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">4</span><span class="p">]</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">todo</span><span class="o">!</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">arr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Default</span>::<span class="n">default</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">arr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bind</span><span class="p">(</span><span class="n">arr</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="205331982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205331982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205331982">(Jul 29 2020 at 08:58)</a>:</h4>
<p><code>arr = bind(arr)</code> currently tries to unify <code>[u8; ?X]</code> with <code>[u8; Unevaluated&lt;?X&gt;(3 + 4)]</code> which fails the occurs check</p>



<a name="205332038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205332038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205332038">(Jul 29 2020 at 08:59)</a>:</h4>
<p>but by discarding all unused substs of <code>3 + 4</code> we would unify <code>[u8; ?X]</code> with <code>[u8; Unevaluated&lt;N&gt;(3 + 4)]</code> which works fine.</p>



<a name="205332075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205332075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205332075">(Jul 29 2020 at 08:59)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> looks like I was once again overeager to just ditch the current <code>ty::Generics</code> entirely <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="205332559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205332559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205332559">(Jul 29 2020 at 09:05)</a>:</h4>
<p>"doing polymorphization" pretty much means using something like <code>query unused_generic_params</code> and replacing all unused params with dummy values here.</p>



<a name="205370664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205370664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205370664">(Jul 29 2020 at 15:15)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040/near/205331260">said</a>:</p>
<blockquote>
<p>Okay, so now that I slept over this and spend a bit more time thinking about it, I wasn't able to think of any big problems with this approach</p>
</blockquote>
<p>what is "this approach" here, the "try to evaluate" approach?</p>



<a name="205370909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205370909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205370909">(Jul 29 2020 at 15:16)</a>:</h4>
<p>"this approach" is using polymorphization to prevent cyclic inference variables here</p>



<a name="205371257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205371257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205371257">(Jul 29 2020 at 15:19)</a>:</h4>
<p>While we might try the "try to evaluate" approach, I am fairly sure that this isn't a good solution, not only because it can cause cycle errors and stuff, but also because the following won't work by doing so:</p>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">M</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">(</span><span class="n">v</span>: <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="p">])</span><span class="w"> </span>-&gt; <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">M</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">     </span><span class="n">todo</span><span class="o">!</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">bar</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">(</span><span class="k">mut</span><span class="w"> </span><span class="n">v</span>: <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="p">])</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">     </span><span class="n">v</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">foo</span><span class="p">(</span><span class="n">v</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="205372547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205372547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205372547">(Jul 29 2020 at 15:29)</a>:</h4>
<p>^ nm, the example here should work,  but there should be examples similar to this where "just evaluating" them won't fix it</p>



<a name="205373577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205373577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205373577">(Jul 29 2020 at 15:36)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040/near/205370909">said</a>:</p>
<blockquote>
<p>"this approach" is using polymorphization to prevent cyclic inference variables here</p>
</blockquote>
<p>I see, I must have missed this somewhere.</p>



<a name="205373601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205373601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205373601">(Jul 29 2020 at 15:37)</a>:</h4>
<p>That's...huh.</p>



<a name="205373644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205373644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205373644">(Jul 29 2020 at 15:37)</a>:</h4>
<p>Yeah, I think it's potentially a good idea, but polymorphization is also intended as a "code size optimization" that we can tweak and change over time, so i'd probably prefer to have a <em>separate</em> analysis</p>



<a name="205373675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205373675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205373675">(Jul 29 2020 at 15:37)</a>:</h4>
<p>I guess it seems like we could figure this out by analyzing the HIR fairly readily in any case</p>



<a name="205373755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205373755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205373755">(Jul 29 2020 at 15:38)</a>:</h4>
<p>But I'm not 100% sure about that :)</p>



<a name="205373842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205373842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205373842">(Jul 29 2020 at 15:39)</a>:</h4>
<p>We can certainly detect references to type parameters or things like <code>&lt;u8 as Foo&lt;T&gt;&gt;::BAR</code></p>



<a name="205373852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205373852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205373852">(Jul 29 2020 at 15:39)</a>:</h4>
<blockquote>
<p>HIR fairly readily</p>
</blockquote>
<p>Isn't that kinda hard when dealing with stuff like this</p>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">test</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="o">&lt;</span><span class="kt">u8</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">Trait</span><span class="o">&gt;</span>::<span class="n">ASSOC</span><span class="p">]</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="kt">u8</span>: <span class="nc">Trait</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w">  </span><span class="p">{</span><span class="w"> </span><span class="n">todo</span><span class="o">!</span><span class="p">()</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="205373875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205373875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205373875">(Jul 29 2020 at 15:39)</a>:</h4>
<p>but checking this on mir is quite easy</p>



<a name="205373881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205373881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205373881">(Jul 29 2020 at 15:39)</a>:</h4>
<p><em>but</em> if you have wacky <code>const fn</code> that have where-clauses .. that might be harder .. have to think about it</p>



<a name="205373918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205373918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205373918">(Jul 29 2020 at 15:39)</a>:</h4>
<p>and as long as we don't use <code>optimized_mir</code> here we also don't have to worry about optimizations</p>



<a name="205373928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205373928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205373928">(Jul 29 2020 at 15:40)</a>:</h4>
<p>really what I meant I guess is checking on "HAIR"</p>



<a name="205373991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205373991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205373991">(Jul 29 2020 at 15:40)</a>:</h4>
<p>or whatever we decided to rename it to</p>



<a name="205374004"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205374004" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205374004">(Jul 29 2020 at 15:40)</a>:</h4>
<p>the distinction between HAIR and "pre-optimization" MIR is slim</p>



<a name="205374031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205374031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205374031">(Jul 29 2020 at 15:40)</a>:</h4>
<p>but the point is that I'd prefer to specify the check separately vs overloading polymorphization</p>



<a name="205374042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205374042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205374042">(Jul 29 2020 at 15:40)</a>:</h4>
<p>in particular I think we're going to want to extend polymorphization to cover cases like:</p>



<a name="205374066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205374066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205374066">(Jul 29 2020 at 15:40)</a>:</h4>
<p>"the type parameter <code>T</code> is used, but the only thing that matters is its size/alignment"</p>



<a name="205374073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205374073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205374073">(Jul 29 2020 at 15:40)</a>:</h4>
<p>or</p>



<a name="205374077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205374077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205374077">(Jul 29 2020 at 15:41)</a>:</h4>
<p>"but we can get away with passing in a vtable"</p>



<a name="205374110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205374110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205374110">(Jul 29 2020 at 15:41)</a>:</h4>
<p>I guess maybe they can ultimately share code and that's ok</p>



<a name="205374129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205374129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205374129">(Jul 29 2020 at 15:41)</a>:</h4>
<p>(i.e., if polymorphization can determine that the type parameter doesn't matter at all...)</p>



<a name="205374171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205374171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205374171">(Jul 29 2020 at 15:41)</a>:</h4>
<p>but I think if we could specify it "syntactically" (taking into account the full expanded form of associated constants) I'd feel more comfortable</p>



<a name="205377431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/occurs%20check%20for%20constants%20%20%2374040/near/205377431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/occurs.20check.20for.20constants.20.20.2374040.html#205377431">(Jul 29 2020 at 16:08)</a>:</h4>
<p>so yeah, tbh I probably won't get to this before we stabilize min_const_generics, so I am satisfied with knowing that a solution exists at all here</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>